var e = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.checkHasImageSaveScope = function() {
    return n.apply(this, arguments);
}, exports.imgSecCheck = function(e) {
    return a.apply(this, arguments);
}, exports.msgSecCheck = function(e) {
    return u.apply(this, arguments);
}, exports.shuffle = function(e) {
    for (var t = e.length - 1; t >= 0; t--) {
        var r = Math.floor(Math.random() * (t + 1)), n = e[r];
        e[r] = e[t], e[t] = n;
    }
    return e;
};

var t = e(require("@babel/runtime/regenerator")), r = e(require("@babel/runtime/helpers/asyncToGenerator"));

function n() {
    return (n = (0, r.default)(t.default.mark(function e() {
        return t.default.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return e.next = 2, wx.promisify(wx.getSetting)();

              case 2:
                if (!1 !== e.sent.authSetting["scope.writePhotosAlbum"]) {
                    e.next = 9;
                    break;
                }
                return e.next = 6, wx.promisify(wx.openSetting)();

              case 6:
                return e.abrupt("return", !1);

              case 9:
                return e.next = 11, wx.promisify(wx.authorize)({
                    scope: "scope.writePhotosAlbum"
                });

              case 11:
                return e.abrupt("return", !0);

              case 12:
              case "end":
                return e.stop();
            }
        }, e);
    }))).apply(this, arguments);
}

function a() {
    return (a = (0, r.default)(t.default.mark(function e(r) {
        return t.default.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return e.abrupt("return", new Promise(function(e) {
                    wx.showLoading({
                        title: "图片检测中..."
                    }), wx.getFileSystemManager().readFile({
                        filePath: r,
                        encoding: "base64",
                        success: function(t) {
                            var r = t.data;
                            wx.cloud.callFunction({
                                name: "imgSecCheck",
                                data: {
                                    imgBase64: r
                                }
                            }).then(function(t) {
                                var r = t.result, n = r.code, a = r.msg;
                                return wx.hideLoading(), -1 === n || "risky content" === a ? (wx.showToast({
                                    title: "图片违规，请更换图片",
                                    icon: "none"
                                }), e(!1)) : e(!0);
                            }).catch(function(t) {
                                return wx.hideLoading(), console.log("微信openApi.imgSecCheck接口返回异常", t), e(!0);
                            });
                        }
                    });
                }));

              case 1:
              case "end":
                return e.stop();
            }
        }, e);
    }))).apply(this, arguments);
}

function u() {
    return (u = (0, r.default)(t.default.mark(function e(r) {
        var n, a, u, o;
        return t.default.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return wx.showLoading({
                    title: "内容检测中..."
                }), e.prev = 1, e.next = 4;

              case 4:
                if (n = e.sent, a = n.result, u = a.code, o = a.msg, wx.hideLoading(), -1 !== u && "risky content" !== o) {
                    e.next = 12;
                    break;
                }
                return wx.showToast({
                    title: "内容违规.",
                    icon: "none"
                }), e.abrupt("return", !1);

              case 12:
                return e.abrupt("return", !0);

              case 15:
                return e.prev = 15, e.t0 = e.catch(1), wx.hideLoading(), console.log("微信openApi.msgSecCheck检测接口异常：", e.t0), 
                e.abrupt("return", !0);

              case 20:
              case "end":
                return e.stop();
            }
        }, e, null, [ [ 1, 15 ] ]);
    }))).apply(this, arguments);
}